//
//  GrowRecordCell.m
//  PigMarket
//
//  Created by mac on 2019/7/3.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "GrowRecordCell.h"

@interface GrowRecordCell ()
/**
 bgView
 */
@property (nonatomic , strong) UIView *bgView;
/**
 img
 */
@property (nonatomic , strong) UIImageView *img;
/**
 icon
 */
@property (nonatomic , strong) UIImageView *icon;
/**
 time
 */
@property (nonatomic , strong) UILabel *timeLab;

@end
@implementation GrowRecordCell

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.img];
    [self.bgView addSubview:self.icon];
    [self.bgView addSubview:self.timeLab];
}

- (void)initLayout {
    // 布局子控件
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(99);
    }];
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(7);
        make.top.mas_equalTo(self.img.mas_bottom).offset(12);
        make.size.mas_equalTo(18);
    }];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(10);
        make.height.mas_equalTo(16);
        make.centerY.mas_equalTo(self.icon.mas_centerY);
        make.right.mas_equalTo(-10);
    }];
}

#pragma mark - getter and setter
- (void)setModel:(GrowRecord *)model {
    _model = model;
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.imgs] placeholderImage:[UIImage imageNamed:@"placeholder_middle"]];
    self.timeLab.text = model.createTime;
}
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.layer.borderWidth = 1;
        _bgView.layer.borderColor = [UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:1.0].CGColor;
        _bgView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
        _bgView.layer.cornerRadius = 3;
        _bgView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.03].CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(3,3);
        _bgView.layer.shadowOpacity = 1;
        _bgView.layer.shadowRadius = 5;
    }
    return _bgView;
}
- (UIImageView *)img {
    if (!_img) {
        _img = [[UIImageView alloc] init];
        
    }
    return _img;
}
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
        _icon.image = [UIImage imageNamed:@"adopted_look_growrecord_icon"];
    }
    return _icon;
}
- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [[UILabel alloc] init];
        _timeLab.textColor = [UIColor colorWithHexString:@"#454545"];
        _timeLab.font = [UIFont systemFontOfSize:13];
    }
    return _timeLab;
}
@end
